<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
	<title>
	<?php if(!empty($pagetitle)): echo ($pagetitle); endif; ?>
</title>
<script type="text/javascript" src="__ROOT__/public/jsLib/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="__ROOT__/public/jsLib/jquery.cookies.2.2.0.min.js"></script>
<script type="text/javascript" src="__ROOT__/asset/js/main.js"></script>
<script type="text/javascript" src="__ROOT__/asset/js/checkfield.js"></script>
<link rel="stylesheet" type="text/css" href="__ROOT__/public/jsLib/bootstrap/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="__ROOT__/public/jsLib/bootstrap/google-code-prettify/prettify.css" />
<link rel="stylesheet" type="text/css" href="__ROOT__/asset/main.css" />
<script type="text/javascript" src="__ROOT__/public/jsLib/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="__ROOT__/public/jsLib/bootstrap/google-code-prettify/prettify.js"></script>
<script type="text/javascript">
	var APP = "__APP__";
	var cookie_prefix = '<?php echo ($cookie_prefix); ?>';
	var app_path = $.cookies.get(cookie_prefix+'config_path');
	var dir = $.cookies.get(cookie_prefix+'base_dir');
	var app_name = $.cookies.get(cookie_prefix+'app_name');
	var version = $.cookies.get(cookie_prefix+'version');
	var app_url=$.cookies.get(cookie_prefix+'app_url');
	$(function () {
		//首页的tooltip绑定
		$('.leftbar>li').tooltip({placement:'right'});
		prettyPrint()
	});
</script>
	<link rel="stylesheet" href="__ROOT__/asset/CodeMirror/lib/codemirror.css">
<link rel="stylesheet" href="__ROOT__/asset/CodeMirror/theme/tphelper.css">
<script src="__ROOT__/asset/CodeMirror/lib/codemirror.js"></script>
<script src="__ROOT__/asset/CodeMirror/lib/util/emmet.min.js"></script>
<script src="__ROOT__/asset/CodeMirror/lib/util/formatting.js"></script>
<!--<script src="__ROOT__/asset/CodeMirror/util/foldcode.js"></script>-->
<script src="__ROOT__/asset/CodeMirror/mode/xml/xml.js"></script>
<script src="__ROOT__/asset/CodeMirror/mode/javascript/javascript.js"></script>
<script src="__ROOT__/asset/CodeMirror/mode/css/css.js"></script>
<script src="__ROOT__/asset/CodeMirror/mode/mysql/mysql.js"></script>
<script src="__ROOT__/asset/CodeMirror/mode/php/php.js"></script>
<script src="__ROOT__/asset/CodeMirror/mode/clike/clike.js"></script>
<script src="__ROOT__/asset/CodeMirror/mode/htmlmixed/htmlmixed.js"></script>
<style type="text/css">
	.CodeMirror-fullscreen {
		display: block;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 2000;
	}
	/*高亮所在行*/
	.activeline {background: #f2f2f2 !important;}
	/*编辑器的初始化高度*/
	.CodeMirror-scroll {
		height: 350px;
	}
</style>
<script type="text/javascript">
	//CodeMirror格式化和注释功能
	function getSelectedRange() {
		return { from:editor.getCursor(true), to:editor.getCursor(false) };
	}
	function autoFormatSelection() {
		var range = getSelectedRange();
		editor.autoFormatRange(range.from, range.to);
	}
	function commentSelection(isComment) {
		var range = getSelectedRange();
		editor.commentRange(isComment, range.from, range.to);
	}
	//CodeMirror全屏功能
	function isFullScreen(cm) {
		return /\bCodeMirror-fullscreen\b/.test(cm.getWrapperElement().className);
	}
	function winHeight() {
		return window.innerHeight || (document.documentElement || document.body).clientHeight;
	}
	function setFullScreen(cm, full) {
		var wrap = cm.getWrapperElement(), scroll = cm.getScrollerElement();
		if (full) {
			wrap.className += " CodeMirror-fullscreen";
			scroll.style.height = winHeight() + "px";
			document.documentElement.style.overflow = "hidden";
		} else {
			wrap.className = wrap.className.replace(" CodeMirror-fullscreen", "");
			scroll.style.height = "";
			document.documentElement.style.overflow = "";
		}
		cm.refresh();
	}
	CodeMirror.defaults.extraKeys={
		"F11":function (cm) {
			setFullScreen(cm, !isFullScreen(cm));
		},
		"Esc":function (cm) {
			if (isFullScreen(cm)) setFullScreen(cm, false);
		}
	}
	var cmoptions={
		lineNumbers   :true,
		matchBrackets :true,
		mode          :"application/x-httpd-php",
		indentUnit    :4,
		gutter        :true,
		fixedGutter   :true,
		indentWithTabs:true,
		lineWrapping  :true,
		enterMode     :"keep",
		tabMode       :"shift",
		theme         :"tphelper"
	};
	var cmid='code-editor';
	//自定义快捷键
	$(function(){
		//初始化编辑器
		window.editor = CodeMirror.fromTextArea(document.getElementById(cmid), cmoptions );
		//高亮所在行
		var hlLine = editor.setLineClass(0, "activeline");
		editor.setOption('onCursorActivity',function () {
			editor.setLineClass(hlLine, null, null);
			hlLine = editor.setLineClass(editor.getCursor().line, null, "activeline")});
		//全屏功能
		CodeMirror.connect(window, "resize", function () {
			var showing = document.body.getElementsByClassName("CodeMirror-fullscreen")[0];
			if (!showing) return;
			showing.CodeMirror.getScrollerElement().style.height = winHeight() + "px";
		});
	})
</script>
	<link rel="stylesheet" href="__ROOT__/asset/markdown.css">
	<script src="__ROOT__/asset/CodeMirror/lib/util/overlay.js"></script>
	<script src="__ROOT__/asset/CodeMirror/mode/markdown/markdown.js"></script>
	<script src="__ROOT__/asset/CodeMirror/mode/gfm/gfm.js"></script>
	<script src="__ROOT__/asset/CodeMirror/showdown/showdown.js"></script>
	<script src="__ROOT__/asset/CodeMirror/showdown/extensions/exts.js"></script>
	<script type="text/javascript">
		cmoptions.mode = 'gfm';
		//'github', 'table', 'prettify','weibo','syntaxhighlighter'
		var converter1 = new Showdown.converter({ extensions:[ 'github', 'table', 'prettify','weibo'] });
		var converter2 = new Showdown.converter({ extensions:[ 'github', 'table', 'syntaxhighlighter','weibo'] });
		$(function () {
			var md_preview = $('.md-preview');
			var code_editor = $('.md-editor');
			var md_html = $('.md-html')
			var md_content = $('.md-content');
			var i = true;
			cmoptions.mode = 'text/html';
			cmoptions.profile = 'xhtml';
			cmoptions.readOnly = true;
			window.editor2 = CodeMirror.fromTextArea(document.getElementById('md-html'), cmoptions);
			$('body').on('keydown', function (e) {
				if (e.ctrlKey) {
					switch (e.keyCode) {
						case 13:
							if (i) {
								var html = converter1.makeHtml(editor.getValue());
								var html2= converter2.makeHtml(editor.getValue());
								if (e.altKey) {
									md_html.css('display', 'block');
									md_preview.css('display', 'none');
									setTimeout(function () {
										editor2.setValue(html2);
									}, 50)
								} else {
									md_preview.html(html);
									md_html.css('display', 'none');
									md_preview.css('display', 'block');
									prettyPrint();
								}
								code_editor.css('display', 'none');
								md_content.css('display', 'block');
								i = false;
							} else {
								md_html.css('display', 'none');
								md_preview.css('display', 'none');
								code_editor.css('display', 'block');
								md_content.css('display', 'none');
								i = true;
							}
							break;
					}
				}
			});
			setInterval(function () {
				localStorage[cookie_prefix+'_md_content'] = editor.getValue();
			}, 5000);
			if (localStorage[cookie_prefix + '_md_content']) {
				editor.setValue(localStorage[cookie_prefix + '_md_content'])
			}
		})
	</script>
	<style type="text/css">
		.CodeMirror-scroll {
			min-height: 500px;
			height: 100%;
		}
	</style>
</head>
<body>
<div class="navbar navbar-fixed-top navbar-inverse">
	<div class="navbar-inner">
		<div class="container">
			<a class="brand" href="__APP__" data-original-title="返回TP助手首页">ThinkPHP助手</a>
			<ul class="nav">
				<li class="divider-vertical"></li>

				<li><a href="" class="app_name" data-original-title="访问项目首页" style="color: #ffffff;font-weight: bold;" target="_blank"></a></li>
			</ul>

			<form class="pull-right" id="docform" action="" method="post" enctype="application/x-www-form-urlencoded" target="_blank">
				<div class="input-prepend input-append">
					<select name="docname" id="docname" class="" onchange="getAction()">
						<option value="php">php</option>
						<option value="jquery">jQuery</option>
						<option value="thinkphp">ThinkPHP</option>
					</select>
					<input name="pattern" class="span2" id="appendedInputButtons" type="text" onchange="getAction()" placeholder="输入函数名或关键词">
					<input type="hidden" name="keywords" value="">
					<input type="hidden" name="show" value="quickref">
					<input type="hidden" name="lang" value="zh">
					<button class="btn" type="submit">搜索</button>
				</div>
			</form>

		</div>
	</div>
</div>

<div class="top-alert alert-error affix" style="display: none;">
	<div class="container ">
		<button class="close" style="margin-top: 4px;">&times;</button>
		<div class="alert alert-error alert-noborder alert-content" style="">
			表单填写有误,请检查红色提示表单项.
		</div>
	</div>
</div>

<script type="text/javascript">
	$('.navbar .app_name').text("当前项目：" + app_name);
	$('.navbar .app_name').attr('href', app_url);
	$('.navbar a').tooltip({placement:'bottom'});
	var search = {
		php     :"http://cn2.php.net/search.php",
		jquery  :'http://api.jquery.com/?ns0=1&s=keywords',
		thinkphp:'http://doc.thinkphp.cn/manual/_search.html'
	}
	function getAction() {
		var keyword = $("input[name='pattern']").val();
		var url = search[$('#docname').val()].replace(/keywords/, keyword);
		$('#docform').attr('action', url);
		$("input[name='keywords']").val(keyword)
	}
	getAction();
</script>
<div class="container content">
	<div class="row body-content">
		<div class='md-editor'>
			<div class="span3">
				<ul class="nav nav-tabs nav-stacked leftbar">
	<li id="config_list" data-original-title="修改当前项目的配置文件">
		<a href="__APP__/Config/index">
			编辑项目配置
			<i class="icon-chevron-right"></i>
		</a>
	</li>
	<li data-original-title="快速向项目中添加常用js库">
		<a href="__APP__/FileManager/getfilelist" id="addlib" class="showform" data-original-title="添加js或css框架到项目目录">添加前端库
		<i class="icon-chevron-right"></i>
		</a>
	</li>
	<li>
		<a href="__APP__/Index/pregTest" id="pcrehelper" class="showform" data-original-title="正则表达式测试">PHP正则助手
		<i class="icon-chevron-right"></i>
		</a>
	</li>
	<li>
		<a href="__APP__/Index/fragmentTest">代码片段测试
		<i class="icon-chevron-right"></i>
		</a>
	</li>
	<li>
		<a href="__APP__/Index/installConsole">安装Console工具
			<i class="icon-chevron-right"></i>
		</a>
	</li>
	<li>
		<a href="__APP__/Index/markdown">Markdown编辑器
			<i class="icon-chevron-right"></i>
		</a>
	</li>
</ul>
<script type="text/javascript">
	$.each($('.leftbar li'),function(){
		if (location.href.indexOf($(this).find('a').attr('href'))>0 ) {
			$(this).addClass('active')
		}
	})
</script>
			</div>
			<div class="span9">

				<div style="border: 1px solid #ebebeb;">
					<textarea name="codeeditor" id="code-editor" style="display: none;"></textarea>
				</div>

			</div>
		</div>
		<div class='span12'>
			<div class='well md-content' style='display:none;background-color: #fff;'>
				<div class='md-html' style='display: none;'>
					<textarea id='md-html' readonly style='width:100%;display: none;'>123
					</textarea>
				</div>
				<div class='md-preview markdown-body' style='display: none;'>

				</div>
			</div>
		</div>
	</div>
</div>
<?php echo ($footer); ?>
</body>
</html>